package com.mew.chess.core.game.pokdeng.game;

import com.mew.chess.core.game.pokdeng.game.common.PokDengConstantValue;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;


/**
 * @author dylin
 */
@Data
public class PokDengRoomManager {
    private int roomId;
    private int[] betArrays;
    private final Map<Integer, PokDengTableManager> tableMangerMap = new ConcurrentHashMap<>(PokDengConstantValue.TABLE_INIT_DEFAULT);//桌子

    private PokDengRoomManager(){}
    public PokDengRoomManager(int roomId, int[] betArrays){
        this.roomId=roomId;
        this.betArrays=betArrays;
    }

    public PokDengTableManager getTableManager(Integer tableId){
        return tableMangerMap.get(tableId);
    }
    public void putTableManger(PokDengTableManager tableManager){
        tableMangerMap.put(tableManager.getTableId(),tableManager);
    }

    public Map<Integer,List<Integer>> getEmptyTable(){
        Map<Integer,List<Integer>> emptyTable=new HashMap<>();
        tableMangerMap.values().stream().forEach(t->{
            List<Integer> emptySeatList=t.getEmptySeat();
            if(emptySeatList.size()>0){
                emptyTable.put(t.getTableId(),emptySeatList);
            }
        });
        return emptyTable;
    }

    //TODO 公共方法不支持  现在先用笨办法 一张桌子一张桌子的找人
    public void exitRoom(long userId){
        for (PokDengTableManager table : tableMangerMap.values()) {
            table.exitRoom(userId);
        }
    }
}

